import {
	ref
} from "vue";

export default function useComment(data, $http) {
	const list = ref([]);

	/*获取文章评论列表*/
	const {
		articleId,
		pageSize,
		page
	} = data;
	const _getCommentList = async () => {
		try {
			const listArr = await $http.get_comments({
				articleId,
				pageSize,
				page,
			});
			list.value = listArr;
			if (listArr.length === 0) {
				return
			};
			return listArr;
		} catch (error) {
			console.error("获取评论列表失败", error);
			list.value = [];
		}
	};

	return {
		list,
		_getCommentList,
	};
}